const express = require("express");
const router = express.Router();
const adminServer = require("../../services/adminService")
const { asyncHandler } = require("../getSendResult");
const jwt = require("../jwt")

router.get("/login",asyncHandler(async (req,res)=>{
    const result = await adminServer.login(req.body.loginId,req.body.loginPwd)
    if (result) {
        jwt.generateToken(res, undefined, {id:result.id})
    }
    return result 
}));

router.get("/whoami",asyncHandler(async (req,res)=>{
    return await adminServer.getAdminById(req.userId)
}))

module.exports = router;